﻿using MediatR;
using Microsoft.EntityFrameworkCore;
using Traceability_Management.Domain;
using Traceability_Management.ErrorCode;
using Traceability_Management.Infrastructure.Interfaces;
using Traceability_Management.Read.Api.Application.Command.ThreeSelectWay;

namespace Traceability_Management.Read.Api.Application.CommandHandler.ThreeSelectWay
{
    public class ShowXianCommandHandler : IRequestHandler<ShowXianCommand, ApiResult<List<Slaughts_Xian>>>
    {
        IBaseReponsitory<Slaughts_Xian> Slaughts_Xian;

        public ShowXianCommandHandler(IBaseReponsitory<Slaughts_Xian> Slaughts_Xian)
        {
            this.Slaughts_Xian = Slaughts_Xian;
        }

        public async Task<ApiResult<List<Slaughts_Xian>>> Handle(ShowXianCommand request, CancellationToken cancellationToken)
        {
            var list = await Slaughts_Xian.GetQuery().Where(c => c.City_Id == request.CityId).ToListAsync();
            return new ApiResult<List<Slaughts_Xian>>
            {
                Code = ApiEnum.False,
                Message = "成功了",
                Data = list
            };
        }
    }
}
